﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PX.File;

public partial class Admin_FileMT : PX.ShowLayer.BaseView
{
	private FileComponent clsFileComp = new FileComponent();
	private FileView clsFileView = new FileView();
	private PX.User.UserComponent clsUserComp = new PX.User.UserComponent();
	private PX.FileMTRight.FileMTRightComponent clsFileMTRightComp = new PX.FileMTRight.FileMTRightComponent();

	public Admin_FileMT()
		: base("idTotal")
	{
		clsView = clsFileView;
		clsFileView.clsPage = Page;

		AddTableColumn(new Tony.Structs.TableShowColumn("文件名", "FileName"));
		AddTableColumn(new Tony.Structs.TableShowColumn("栏目", "Column", 200));
		AddTableColumn(new Tony.Structs.TableShowColumn("上传时间", "ShowDate", 100));

		lBtnEdit.Visible = false;

	}

	protected override void OnInit(EventArgs e)
	{
		int nRight = 0;

		clsFileView.strRights = Session["LoginUserRight"].ToString();
		clsFileView.nUserID = Convert.ToInt32(Session["LoginUserID"]);
		clsFileView.nDepartmentID = Convert.ToInt32(Session["LoginUserDepartmentID"]);
		base.OnInit(e);

		PX.User.User clsUser = (PX.User.User) clsUserComp.GetOneByID(Convert.ToInt32(Session["LoginUserID"]));
		nRight = clsFileMTRightComp.QueryRight(clsUser.UserGroupID);

		if (nRight == clsFileComp._clsConfig.nFileMTRight_Oneself)
		{
			clsFileView.bQueryByUserID = true;
		}
		else
		{
			if (nRight == clsFileComp._clsConfig.nFileMTRight_Department)
			{
				clsFileView.bQueryByDepartmentID = true;
			}
			else
			{
				if (nRight == clsFileComp._clsConfig.nFileMTRight_All)
				{
					clsFileView.bQueryByUserID = false;
					clsFileView.bQueryByDepartmentID = false;
				}
				else
				{
					clsFileView.bQueryByUserID = true;
				}
			}
		}

		gvTable.RowDataBound += new GridViewRowEventHandler(gvTable_RowDataBound);
	}

	void gvTable_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		int nID = 0;

		if (e.Row.RowIndex >= 0)
		{
			for (int i = 0; i < e.Row.Cells.Count; i++)
			{
				//if ((i != 0)  (i != (e.Row.Cells.Count - 1)))
				if ((i != 0) && (i != (e.Row.Cells.Count - 1)))
				{
					//LinkButton lBtnRead2 = new LinkButton();

					//lBtnRead2.Text = e.Row.Cells[i].Text;
					//lBtnRead2.CommandArgument = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();
					//lBtnRead2.CommandName = lBtnRead.CommandName;
					//lBtnRead2.CssClass = lBtnRead.CssClass;

					PX.File.File clsFile = new File();

					nID = Convert.ToInt32(((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString());

					clsFile = (PX.File.File) clsFileComp.GetOneByID(nID);

					e.Row.Cells[i].Controls.Clear();
					HyperLink aLink = new HyperLink();

					aLink.CssClass = "Read";
					aLink.Text = e.Row.Cells[i].Text;
					aLink.NavigateUrl = "../ShowFile.aspx?FileID=" + nID.ToString();
					aLink.Target = "_blank";

					e.Row.Cells[i].Controls.Add(aLink);
				}
			}
		}
	}

	protected void Page_Load(object sender, EventArgs e)
	{

	}

	#region 控件设置
	protected override void SetControlText()
	{
		base.SetControlText();

		lBtnShowAdd.Text = "文件上传";
	}

	protected override void SetControlCSS()
	{
		base.SetControlCSS();

		pFloat.CssClass = pFloat.CssClass + " file";
	}
	#endregion 控件设置


}
